package com.lz.football.module.rankinglist
{
	import com.common.stdlib.ArrayUtil;
	import com.lz.football.module.base.IComponent;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.text.TextField;
	
	import lz.controls.nick.PagePanel;

	/**
	 *排行基础面板 
	 * @author Administrator
	 * 
	 */	
	public class RankingBaseView extends Sprite implements IComponent
	{
		protected var skin:MovieClip;
		/**
		 *换页 
		 */
		protected var _page:PagePanel;
		/**
		 *列表容器 
		 */
		protected var listContain:MovieClip;
		/**
		 *每页数量 
		 */
		protected var page_num:int;
		/**
		 *排名 
		 */
		private var _rank:TextField;
		/**
		 * 
		 */
		private var _list:Array;
		
		/**
		 * 
		 */
		private var itemVec:Vector.<RankingItem>;
		/**
		 *类型 
		 */
		public var type:TextField;
		
		/**
		 *1为综合排名 2为国家排名  
		 */
		public var view_type:int = 1;
		public function RankingBaseView()
		{
			super();
		}
		
		public function initUI(view:Object=null):void
		{
			if(skin == null)return;
			listContain = skin.listContain;
			_rank = skin.rank;
			_page = new PagePanel();
			_page.initUI("com.lz.commonUI.turnPage_white");
			_page.callBack = turnPage;
			this.addChild(_page);
			_page.x = 265;
			_page.y = 345;
			initItem();
		}
		
		private function initItem():void
		{
			itemVec = new Vector.<RankingItem>();
			var item:RankingItem;
			for(var i:int = 0;i < page_num;i++)
			{
				item = new RankingItem();
				item.initUI();
				itemVec.push(item);
				item.y = (26) * i;
//				listContain.addChild(item);
			}
		}
		/**
		 * 
		 * 
		 */
		public function setDate($obj:Object):void
		{
			if($obj == null)return;
			_list = $obj.list;
			if($obj.selfrank > 0)
				_rank.text = "我的排名：" + $obj.selfrank + "";
			else
				_rank.text = "不在排名内";
			_page.max = Math.ceil(_list.length/page_num);
			if(_page.max <=0)_page.max = 1;
			_page.min = 1;
			turnPage();
		}
		
		
		
		/**
		 *换页 
		 * @param type
		 * 
		 */
		private function turnPage(type:String = ""):void
		{
			reset();
			var arr:Array = ArrayUtil.getPageSizeDatas(_page.min,page_num,_list);
			var len:int = arr.length;
			for(var i:int = 0;i < len;i++)
			{
				itemVec[i].setdate(arr[i]);
				listContain.addChild(itemVec[i]);
				if(view_type == 2)
				{
					itemVec[i].setNationSort();
				}
			}
		}
		
		private function reset():void
		{
			while(listContain.numChildren)
			{
				listContain.removeChildAt(0);
			}
		}
		public function addEvtListener():void
		{
		}
		
		public function removeEvtListener():void
		{
		}
		
		public function destroyView():void
		{
			while(itemVec.length)
			{
				itemVec.pop().destroyView();
			}
			itemVec = null;
			removeEvtListener();
		}
	}
}